/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Demo;

import BussinessLayer.MembersFactory;
import BussinessLayer.ReportsFactory;
import DTO.Member.MemberList;
import DTO.Member.Members;
import DTO.Member.Members.MembersFields;
import DTO.Report.ReportList;
import DTO.Rule.RuleList;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author TrucTM
 */
public class DemoClass {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            MembersFactory memberfactory = new MembersFactory();
            MemberList listmember = new MemberList();
            List<Members> list_temp1 = new ArrayList<Members>();
            list_temp1 = memberfactory.GetNameSpace("2");
           // list_temp1 = memberfactory.GetAll();
            //List<Members> listItemMemberTemp_1 = memberfactory.GetAll();
            listmember.setMember(memberfactory.GetAll());
            JAXBContext ctx = JAXBContext.newInstance(listmember.getClass());
            Marshaller mar = ctx.createMarshaller();
            mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            mar.marshal(listmember, new File("src/java/XMLSchema/member.xml"));
            JAXBContext jc = JAXBContext.newInstance(MemberList.class);
            Unmarshaller u = jc.createUnmarshaller();
            File f = new File("src/java/XMLSchema/member.xml");
            // JAXBElement tmp = (JAXBElement) u.unmarshal(f);
            //MemberList item = (MemberList) tmp.getValue();
            MemberList item = (MemberList) u.unmarshal(f);

            ReportList listreport = new ReportList();
            ReportsFactory reportFactory = new ReportsFactory();
            listreport.setReport(reportFactory.GetAll());
//            System.out.println("trtrtr " + listreport.getReport().size());
            ctx = JAXBContext.newInstance(ReportList.class);
            mar = ctx.createMarshaller();
            mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            mar.marshal(listreport, new File("src/java/XMLSchema/report.xml"));
            jc = JAXBContext.newInstance(RuleList.class);
            u = jc.createUnmarshaller();
            f = new File("src/java/XMLSchema/rules.xml");
            // JAXBElemenuhmt tmp = (JAXBElement) u.unmarshal(f);
            //MemberList item = (MemberList) tmp.getValue();
            RuleList itemReport = (RuleList) u.unmarshal(f);
            //item.setMember(memberfactory.GetNameSpace("2"));
            List<Members> listItemMember = new ArrayList<Members>();
            //listItemMember = memberfactory.GetNameSpace("2");
//            memberfactory.GetNameSpace("2",listItemMember);
            memberfactory = new MembersFactory();
            listItemMember = memberfactory.GetAllBy(MembersFields.MemCode, "NguyenHuynhLong1");
            //List<Members> listItemMember_1 = new ArrayList<Members>();
            //listItemMember_1 = memberfactory.GetNameSpace("2");
            Members listMember = new Members();
            memberfactory = new MembersFactory();
            listMember = memberfactory.GetByPrimaryKey(2);

            item.setMember(memberfactory.GetAllBy(MembersFields.MemCode, "NguyenHuynhLong1"));
            System.out.println("Length: " + item.getMember().size());

        } catch (JAXBException ex) {
            Logger.getLogger(DemoClass.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
